import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 数据组管理
 * @date: 2019/7/11

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询数据组列表
 * @param {any} params - 查询参数
 */

export function queryList() {
  return _queryList.apply(this, arguments);
}
/**
 * 新建数据组
 * @param {object} data - 新建表单
 */

function _queryList() {
  _queryList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var params,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-groups") : "".concat(CPAAS_PLATFORM, "/v1/data-groups"), {
              query: parseParameters(params)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryList.apply(this, arguments);
}

export function createDataGroup(_x) {
  return _createDataGroup.apply(this, arguments);
}
/**
 * 查询数据组头信息
 * @param {string} params - 数据组ID
 */

function _createDataGroup() {
  _createDataGroup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-groups") : "".concat(CPAAS_PLATFORM, "/v1/data-groups"), {
              method: 'POST',
              body: _objectSpread({}, data)
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createDataGroup.apply(this, arguments);
}

export function queryDataGroupHead(_x2) {
  return _queryDataGroupHead.apply(this, arguments);
}
/**
 * 更新数据组头信息
 * @param {object} data - 表单数据
 */

function _queryDataGroupHead() {
  _queryDataGroupHead = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(dataGroupId) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-groups/").concat(dataGroupId) : "".concat(CPAAS_PLATFORM, "/v1/data-groups/").concat(dataGroupId)));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryDataGroupHead.apply(this, arguments);
}

export function updateDataGroupHead(_x3) {
  return _updateDataGroupHead.apply(this, arguments);
}
/**
 * 查询数据组行列表数据
 * @param {string} params - 数据组ID
 */

function _updateDataGroupHead() {
  _updateDataGroupHead = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(data) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-groups") : "".concat(CPAAS_PLATFORM, "/v1/data-groups"), {
              method: 'PUT',
              body: _objectSpread({}, data)
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateDataGroupHead.apply(this, arguments);
}

export function queryLineList(_x4) {
  return _queryLineList.apply(this, arguments);
} // 查询选择维度代码弹窗数据

function _queryLineList() {
  _queryLineList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var groupId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            groupId = params.groupId;
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-lines/").concat(groupId) : "".concat(CPAAS_PLATFORM, "/v1/data-lines/").concat(groupId), {
              query: parseParameters(params)
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryLineList.apply(this, arguments);
}

export function queryModalList(_x5) {
  return _queryModalList.apply(this, arguments);
}
/**
 * 新建数据组行
 * @param {object} data - 请求数据
 */

function _queryModalList() {
  _queryModalList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-group-dimension") : "".concat(CPAAS_PLATFORM, "/v1/data-group-dimension"), {
              query: parseParameters(params)
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryModalList.apply(this, arguments);
}

export function createDataGroupLine(_x6) {
  return _createDataGroupLine.apply(this, arguments);
}
/**
 * 删除数据组行
 * @param {object} params - 请求数据
 */

function _createDataGroupLine() {
  _createDataGroupLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(data) {
    var dataGroupId, dataGroupLine;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            dataGroupId = data.dataGroupId, dataGroupLine = data.dataGroupLine;
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-lines/").concat(dataGroupId) : "".concat(CPAAS_PLATFORM, "/v1/data-lines/").concat(dataGroupId), {
              method: 'POST',
              body: _toConsumableArray(dataGroupLine)
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _createDataGroupLine.apply(this, arguments);
}

export function deleteDataGroupLine(_x7) {
  return _deleteDataGroupLine.apply(this, arguments);
} // 查询分配值列表数据

function _deleteDataGroupLine() {
  _deleteDataGroupLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(data) {
    var dataGroupId, dataGroupLine;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            dataGroupId = data.dataGroupId, dataGroupLine = data.dataGroupLine;
            return _context8.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-lines/").concat(dataGroupId) : "".concat(CPAAS_PLATFORM, "/v1/data-lines/").concat(dataGroupId), {
              method: 'DELETE',
              body: _toConsumableArray(dataGroupLine)
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _deleteDataGroupLine.apply(this, arguments);
}

export function queryAssignedValueList(_x8) {
  return _queryAssignedValueList.apply(this, arguments);
}
/**
 * 新建分配值
 * @param {object} data - 请求数据
 */

function _queryAssignedValueList() {
  _queryAssignedValueList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    var groupLineId;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            groupLineId = params.groupLineId;
            return _context9.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-dtls/").concat(groupLineId) : "".concat(CPAAS_PLATFORM, "/v1/data-dtls/").concat(groupLineId), {
              query: parseParameters(params)
            }));

          case 2:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _queryAssignedValueList.apply(this, arguments);
}

export function createAssignedValue(_x9) {
  return _createAssignedValue.apply(this, arguments);
} // 查询选择维度值的弹窗数据

function _createAssignedValue() {
  _createAssignedValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(data) {
    var groupLineId, dataGroupDtlList;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            groupLineId = data.groupLineId, dataGroupDtlList = data.dataGroupDtlList;
            return _context10.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-dtls/").concat(groupLineId) : "".concat(CPAAS_PLATFORM, "/v1/data-dtls/").concat(groupLineId), {
              method: 'POST',
              body: _toConsumableArray(dataGroupDtlList)
            }));

          case 2:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _createAssignedValue.apply(this, arguments);
}

export function queryValueModalList(_x10) {
  return _queryValueModalList.apply(this, arguments);
}
/**
 * 删除分配值
 * @param {object} params - 请求数据
 */

function _queryValueModalList() {
  _queryValueModalList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    var lovId;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            lovId = params.lovId;
            return _context11.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-group-dimension/").concat(lovId) : "".concat(CPAAS_PLATFORM, "/v1/data-group-dimension/").concat(lovId), {
              query: parseParameters(params)
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _queryValueModalList.apply(this, arguments);
}

export function deleteAssignedValue(_x11) {
  return _deleteAssignedValue.apply(this, arguments);
}

function _deleteAssignedValue() {
  _deleteAssignedValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(data) {
    var groupLineId, dataGroupDtlList;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            groupLineId = data.groupLineId, dataGroupDtlList = data.dataGroupDtlList;
            return _context12.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/data-dtls/").concat(groupLineId) : "".concat(CPAAS_PLATFORM, "/v1/data-dtls/").concat(groupLineId), {
              method: 'DELETE',
              body: _toConsumableArray(dataGroupDtlList)
            }));

          case 2:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _deleteAssignedValue.apply(this, arguments);
}